package org.zachary.prosocialbehaviorservice.infrastructure.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import org.zachary.prosocialbehaviorservice.domain.aggregate_model.activity.ActivityToItem;

import java.util.List;
import java.util.Optional;

public interface SpringDataActivityToItemRepository extends JpaRepository<ActivityToItem, Integer> {
    List<ActivityToItem> findByActivityId(Integer activityId);

    @Transactional
    @Modifying
    @Query("DELETE FROM ActivityToItem e WHERE e.itemId = :itemId")
    void deleteByItemId(@Param("itemId") Integer itemId);

    @Query("SELECT ati.activityId FROM ActivityToItem ati WHERE ati.itemId=:id")
    Optional<Integer> findActivityIdByItemId(@Param("id") Integer id);
    @Query("SELECT ati FROM ActivityToItem ati WHERE ati.itemId=:itemId")
    Optional<ActivityToItem> findByItemId(@Param("itemId") Integer itemId);


//    @Query("SELECT ita.activity.id FROM ItemToActivity ita WHERE ita.item.id = :itemId")
//    Optional<Integer> findActivityIdByItemId(@Param("itemId") Integer itemId);
}
